package com.dbxt.util;

import java.io.BufferedWriter;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;

import javax.servlet.http.HttpServletRequest;

import org.junit.Test;

import com.alibaba.fastjson.JSONObject;
import com.aspose.words.Document;
import com.aspose.words.ExportHeadersFootersMode;
import com.aspose.words.HtmlSaveOptions;

public class AsposeWord {
	
	public  JSONObject parseWord2Html(String path,HttpServletRequest request) throws Exception{
		JSONObject json = new JSONObject();
		
		Document doc = new Document(request.getServletContext().getRealPath("/files") + "/paper/"+path);//path为word地址
		HtmlSaveOptions hso = new HtmlSaveOptions();
		hso.setExportRoundtripInformation(true);
		
		doc.save(request.getServletContext().getRealPath("/files") + "/paper/"+path+".html", hso);//保存html，path+".html"为我定义的生成html的名字
		
		json.put("path", path+".html");
		return json;
	}
	public  JSONObject parseWord2Html2(String path,HttpServletRequest request) throws Exception{
		JSONObject json = new JSONObject();
		
		Document doc = new Document(request.getServletContext().getRealPath("/files") + "/charter/"+path);//path为word地址 查找文档位置
		HtmlSaveOptions hso = new HtmlSaveOptions();
		
		hso.setExportRoundtripInformation(true);
		
		doc.save(request.getServletContext().getRealPath("/files") + "/charter/"+path+".html", hso);//保存html，path+".html"为我定义的生成html的名字
		
		json.put("path", path+".html");
		return json;
	}
//	public  JSONObject parsePDF2Html(String path,HttpServletRequest request) throws Exception{
//		JSONObject json = new JSONObject();
//		
//		Document doc = new Document(request.getServletContext().getRealPath("/files") + "/paper/"+path);//path为word地址
////		HtmlSaveOptions hso = new HtmlSaveOptions();
////		hso.setExportRoundtripInformation(true);
////		
//		doc.save(request.getServletContext().getRealPath("/files") + "/paper/"+path);//保存html，path+".html"为我定义的生成html的名字
//		
//		json.put("path", path);
//		return json;
//	}	
//	public  JSONObject parsePDF2Html2(String path,HttpServletRequest request) throws Exception{
//		JSONObject json = new JSONObject();
//		
//		Document doc = new Document(request.getServletContext().getRealPath("/files") + "/charter/"+path);//path为word地址 查找文档位置
////		HtmlSaveOptions hso = new HtmlSaveOptions();
////		
////		hso.setExportRoundtripInformation(true);
//		
//		doc.save(request.getServletContext().getRealPath("/files") + "/charter/"+path);//保存html，path+".html"为我定义的生成html的名字
//		
//		json.put("path", path);
//		return json;
//	}
}

